home *** CD-ROM | disk | FTP | other *** search
- /* eshot.c */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h> /* sin,cos を使うために */
- #include <sys/iocs.h>
- #include "XSP2lib.H"
-
- #define PCG_MAX 32 /* パターンデータの個数 */
-
-
- static char pcg_alt[PCG_MAX + 1]; /* PCG配置管理テーブル */
- static char pcg_dat[PCG_MAX * 128]; /* PCGデータファイル読み込みバッファ */
-
- static unsigned short pal_dat[16][15]; /* パレットデータ */
-
-
- #define ESHOT_MAX 200 /* 敵弾最大数 */
- #define ESHOT_SPEED 0.75 /* 敵弾の速度 */
-
-
- /* 敵弾構造体 */
- typedef struct _eshot {
- /* 以下の4項目は xsp_set_st() で使うため順不同 */
- signed short x; /* 敵弾のX座標 */
- signed short y; /* 〃 Y座標 */
- short pt; /* スプライトパターンNo. */
- short info; /* 反転コード・色・優先度を表わすデータ */
-
- unsigned char type; /* 〃 種類 */
- unsigned char angle; /* 角度 (0~255) */
- signed int lx, ly; /* 32bit X,Y 座標 ( l = longword ) */
- signed int vx, vy; /* 32bit X,Y 速度 ( v = velocity ) */
- struct _eshot *next; /* 次の構造体へのポインタ */
- } ESHOT;
-
- ESHOT *eshot_top; /* 使用中のワークのリスト */
- ESHOT *eshot_null_top; /* 未使用ワークのリスト */
- ESHOT eshot[ESHOT_MAX]; /* ワーク */
-
- /* EshotAlloc の引き数構造体 */
- typedef struct {
- signed short x; /* 敵弾のX座標 */
- signed short y; /* 〃 Y座標 */
- unsigned char type; /* 〃 種類 */
- unsigned char angle; /* 角度 (0~255) */
- } ESHOTA;
-
-
- #define EshotAlloc(eshot_x,eshot_y,eshot_type,eshot_angle) \
- {\
- ESHOTA eshota, *_eshota = &eshota;\
- _eshota->x = eshot_x;\
- _eshota->y = eshot_y;\
- _eshota->type = eshot_type;\
- _eshota->angle = eshot_angle;\
- EshotAllocF (_eshota);\
- }
-
-
-
- typedef struct {
- signed int x, y;
- } VECTOR;
-
- VECTOR xytable[256]; /* sin,cos テーブル */
-
-
-
- /* ゲーム開始時に呼ばれる */
- void EshotInit (void)
- {
- int i;
-
- /* リストをつなげる */
- eshot_top = NULL;
- eshot_null_top = eshot;
- for (i = 0; i < ESHOT_MAX; i++)
- eshot[i].next = &eshot[i + 1]; /* 次を指すようにする */
-
- eshot[ESHOT_MAX - 1].next = NULL; /* 「一番最後の次」はない */
- }
-
-
-
- /* 敵弾出現時に呼ばれる */
- /* 引き数 : ESHOTA 構造体 */
- void EshotAllocF (ESHOTA * a)
- {
- ESHOT *p;
-
- if (eshot_null_top == NULL) /* ワークの空きはあるか? */
- return;
-
- p = eshot_null_top;
- eshot_null_top = p->next;
- p->next = eshot_top;
- eshot_top = p;
-
- p->lx = (a->x - 8) << 16; /* (8,8) がスプライト座標の中心なので補正 */
- p->ly = (a->y - 8) << 16;
- {
- int a_angle = a->angle;
- p->vx = xytable[a_angle].x;
- p->vy = xytable[a_angle].y;
- }
- p->pt = p->type = a->type; /* スプライトパターン番号 */
- p->info = 0x033f; /* 反転コード・色・優先度を表わすデータ */
- }
-
-
-
- /* 垂直同期ごとに呼ばれる */
- void EshotMove (void)
- {
- ESHOT *p, *q;
-
- p = eshot_top; /* 現在注目しているワーク */
- q = NULL; /* 1つ前のワーク(ワーク削除時に必要) */
-
- while (p != NULL) {
- signed short p_x, p_y; /* p->x, p->y と同じ */
-
- /* 速度を足して上位ワード(固定整数部)だけ取り出す */
- p_x = p->x = (p->lx += p->vx) >> 16;
- p_y = p->y = (p->ly += p->vy) >> 16;
-
-
- /* 敵弾が画面外に出たか? */
- /* (画面右から出た判定と左から出た判定を1回の比較で行っている) */
- if (((unsigned short) p_x > 256 + 16) || ((unsigned short) p_y > 256 + 16)) {
- /* 画面外に出たので消去 */
- if (q == NULL) { /* リストの一番最初を削除 */
- eshot_top = p->next;
- p->next = eshot_null_top;
- eshot_null_top = p;
- q = NULL;
- p = eshot_top;
- } else {
- q->next = p->next;
- p->next = eshot_null_top;
- eshot_null_top = p;
- p = q->next;
- }
- } else {
- xsp_set_st (p);
-
- q = p;
- p = p->next;
- }
- }
- }
-
-
-
- int main (int argc, char *argv[])
- {
- FILE *fp;
- int i, j;
- int game_over = 0;
- unsigned char angle = 0; /* 次に撃つ弾の角度 */
- unsigned char type = 1; /* 次に撃つ弾の種類 */
- int sprites; /* スプライトの枚数 */
-
- if (argc != 1) {
- printf (
- "敵弾テストその7(完璧版) ESHOT.X\n"
- " programmed by Mitsuky <FreeSoftware>\n"
- "\n"
- );
- exit (-1);
- }
- printf ("データテーブルを作成します。\n");
- for (i = 0; i < 256; i++) {
- xytable[i].x = (signed int) (cos (2.0 * M_PI * (long) i / 256.0) * 65536.0 * ESHOT_SPEED);
- xytable[i].y = (signed int) (sin (2.0 * M_PI * (long) i / 256.0) * 65536.0 * ESHOT_SPEED);
- }
-
-
- _iocs_crtmod (10); /* 256x256ドット グラフィック画面 256色 2画面 */
- _iocs_g_clr_on (); /* グラフィック画面の初期化 */
- _iocs_sp_init (); /* スプライトの初期化 */
- _iocs_sp_on ();
-
- /* pcg_dat にパターンデータを読み込む */
- fp = fopen ("ESHOT.SP", "rb");
- fread (pcg_dat, sizeof (char), PCG_MAX * 128, fp);
- fclose (fp);
-
- /* pal_buf に一旦パレットデータを読み込む */
- fp = fopen ("ESHOT.PAL", "rb");
- fread (pal_dat, sizeof (unsigned short), 16 * 15, fp);
- fclose (fp);
- /* パレットデータを定義 */
- /* (1パレットブロック=16色) × (15ブロックぶん) 定義する */
- {
- unsigned short *p = (unsigned short *) pal_dat;
- for (i = 1; i < 15; i++)
- for (j = 0; j < 16; j++)
- _iocs_spalet (0x80000000 | j, i, *p++);
- }
-
- xsp_on ();
- xsp_mode (3);
- /* パターンデータを定義 */
- xsp_pcgdat_set (pcg_dat, pcg_alt, sizeof (pcg_alt));
-
- /* グラフィック画面に線を引く */
- {
- struct _lineptr lp;
- lp.x1 = 0;
- lp.y1 = 128;
- lp.x2 = 255;
- lp.y2 = 128;
- lp.color = 15;
- lp.linestyle = 0xaaaa;
- _iocs_line (&lp);
- lp.x1 = 128;
- lp.y1 = 0;
- lp.x2 = 128;
- lp.y2 = 255;
- _iocs_line (&lp);
- }
-
- printf ("ジョイスティックの\n"
- " [B] ボタンを押すと弾を撃ちます\n"
- " [A] ボタンを押すと終了します\n");
-
-
- EshotInit ();
-
- do {
- xsp_vsync (0); /* 垂直同期待ち */
- j = _iocs_joyget (0); /* ジョイスティック0番 */
-
- /* [A] ボタンが押されたか? */
- if ((j & 0b00100000) == 0)
- game_over = !0; /* ゲームオーバーに */
-
- /* [B] ボタンが押されたか? */
- if ((j & 0b1000000) == 0) {
- /* 種類 type の敵弾を座標(144,144)、角度 angle で発生 */
- #if 0
- /* ここと#else以降は等価(マクロにしただけ) */
- {
- ESHOTA eshota, *_eshota = &eshota;
- _eshota->x = 144;
- _eshota->y = 144;
- _eshota->type = type;
- _eshota->angle = angle;
- EshotAllocF (_eshota);
- }
- #else
- EshotAlloc (144, 144, type, angle);
- #endif
- angle += 8; /* 角度を進める */
- type++; /* 種類を進める(意味無し) */
- if (type > 5)
- type = 1;
- }
- EshotMove ();
- sprites = xsp_out (); /* 表示 */
-
- printf ("弾数 = %3d \n\x0b", sprites);
- /* 0x0b はカーソルを1行上に移動する */
- /* Human68K ユーザーズマニュアルの付録 ASCII 制御コードの欄参照 */
- } while (!game_over);
-
- xsp_off ();
-
- _iocs_crtmod (16);
- return (0);
- }
-